<?php
require('conn.php');
require('functions.php');
require('session.php');
if($userdata['realname']=='' || $userdata['alipay']==''){
		echo "<script>alert('请填写正确收款姓名和支付宝帐号');location.href='zl.php'</script>";
		exit;	
}
//提现金额不足最小提现
// if($userdata['money']<$ti){
		// echo "<script>alert('最低提现金额{$ti}，你的余额不足');location.href='ucenter.php'</script>";
		// exit;		
// }

//提现
if($_POST){
	$money=guolv($_POST['moneynum']);
	$realname=guolv($_POST['realname']);
	$alipay=guolv($_POST['alipay']);
    
	//$yzm=guolv($_POST['yzm']);
	if($alipay=='' || $realname==''){
		echo "<script>alert('请填写正确收款姓名和支付宝帐号');location.href='zl.php'</script>";
		exit;		
	}
	if(is_zzs($money)==false){
		echo "<script>alert('提现金额必须是整数');location.href='tx.php'</script>";
		exit;
	}
	if($money<$ti){
		echo "<script>alert('最低提现金额{$ti}');location.href='tx.php'</script>";
		exit;
	}	
	if(is_numeric($money)==false){
		echo "<script>alert('提现金额必须是整数');location.href='tx.php'</script>";
		exit;		
	}
	if($money>$userdata['money']){
		echo "<script>alert('提现金额超过你的余额');location.href='tx.php'</script>";
		exit;			
	}
	
	// if($yzm=='' || $yzm!==$_COOKIE['yzm']){
		// echo "<script>alert('你输入的手机验证码错误');location.href='tx.php'</script>";
		// exit;			
	// }
	
	if($realname!=='' && $alipay!==''){
		$arr=array(
			//'id'=>null,
			'uid'=>$userdata['id'],
			'sx1'=>$session['tj_id'],//1级上线
			'realname'=>$realname,
			'phone'=>$userdata['phone'],
			'alipay'=>$alipay,
            'alipaypic'=>$userdata['pic'],
			'money'=>$money,
			'state'=>0,
			'time'=>time(),
			
		);
		$values=arr2s($arr);
		$mysql->query("update `userdata` set `money`=`money`-{$money} where `id`='{$userdata['id']}'");
		$mysql->execute("insert into `txdata` {$values}");
		$id=mysql_insert_id();
		if($id!==0){
			echo "<script>alert('提现申请成功，等待支付');location.href='txlist.php'</script>";
			exit;			
		}
	}
}
?>


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title>申请提现 - <?php echo $config['sitename']?></title>
<meta name="keywords" content="<?php echo $config['sitename']?>,提现,申请提现" />
<meta name="description" content="<?php echo $config['sitename']?>申请提现入口">
<link href="Css1/base.css" rel="stylesheet" type="text/css" />
<link href="Css1/header.css" rel="stylesheet" type="text/css" />
<link href="Css1/weiui.css" rel="stylesheet" type="text/css" />
<link href="Css1/form.css" rel="stylesheet" type="text/css" />
<link href="Css1/record.css" rel="stylesheet" type="text/css" />
<link href="Css1/cash.css" rel="stylesheet" type="text/css" />
<script type=text/javascript > var app="/user" </script>
<script type="text/javascript" src="Scripts1/jquery.min.js"></script>
<script type=text/javascript src="Scripts1/jquery.common.js"></script>
<style type="text/css">
<!--
.STYLE1 {
	font-size: 14px;
	font-weight: bold;
	color: #3d3f45;
}
-->
</style>
</head>
<script>
function yzm(){
    var ifrm = document.getElementsByName('iframe')[0];  
    ifrm = document.getElementById('iframe');  
    ifrm.src = 'yzm.php';
}
</script>
<body class="mhome">
 <form class="contact_form" action="tx.php" name="form1" method="post">
<?php include('header.php')?>
 <script>
	(function () {
		var menustate = document.getElementById('g-menustate');
		menustate.addEventListener("click", function (e) {
			if (menustate.checked) {
				$('#g-menustate').addClass('g-noscroll')
			}else {
				$('#g-menustate').removeClass('g-noscroll')
			}
		});
	})();
</script><div class="getcash-page">
            <div class="infos fn-tc fn-color-white">
                <div class="txt-t fn-color-orange">可提现分享币</div>
                <div class="amount"><?php echo $userdata['money']?></div>
                <div class="txt-b"> </div>
            </div>

            <div class="input-box">
                <span class="label fn-color-black">支付方式:</span>
                <div name="bankcard" style="line-height: 42px;" class="input-num fn-color-black">支付宝</div>
            </div>
          
            <!--<div class="input-box">
                <span class="label fn-color-black">手续费:</span>
                <div name="bankcard" style="line-height: 42px;" class="input-num fn-color-red">1元/笔</div>
            </div>-->
            <div class="input-box">
                <span class="label fn-color-black">选择金额:</span>
 
          
          	  <input type="text" maxlength="12" id="moneynum" name="moneynum" value="" placeholder="最低提现<?php echo $config['ti']?>元"  class="input-num">
            </div>
           
			 <div class="input-box">
			 <span class="label fn-color-black">真实姓名：</span>
			  <input type="text" maxlength="12" id="name" name="realname" value="<?php echo $userdata['realname']?>" placeholder="请输入支付宝收款真实姓名"  class="input-num">
			 </div>
			 <div class="input-box">
			 <span class="label fn-color-black">支付宝：</span>
			  <input type="text" maxlength="30" id="account" name="alipay" value="<?php echo $userdata['alipay']?>" placeholder="支付宝帐号为手机或邮箱"  class="input-num">
			 </div>
			 <div class="input-box">
			 <span class="label fn-color-black">确认账号：</span>
			  <input type="text" maxlength="30" id="account1" name="alipay1" value="<?php echo $userdata['alipay']?>" placeholder="请确认支付宝帐号"  class="input-num">
			 </div>
<!--<div class="input-box">
			 <span class="label fn-color-black">确认密码：</span>
			  <input maxlength="12" type="password" id="password" name="password" placeholder="请输入分享赚密码"  class="input-num">
			 </div>-->
            <div class="remind">
                <div align="center" class="STYLE1">
                  <p>&nbsp;</p>
                  <p>收款二维码                  </p>
                </div>
                <div align="center"><img src=".<?php echo $userdata['pic']?>" alt="" width="174" height="149" align="middle"/></div>
                <div class="remind-text fn-color-grey">每日可提现1次，预计到账时间1-3个工作日</div>
    </div>
    <input name="getcash" class="big-btn bg-btn-orange mt20 csbutton" type="button" value="立即提现" href="javascript:;" onClick="firm()">
</div>
<div class="act-dialog_mod" style="display:none;" id="masks">
<div class="act-dialog" id="copyurl" style="display:none;">
<div class="act-dialog_bd">
<div class="act-dialog_suc">
<div class="act-dialog_suc__info">
<h4 class="act-dialog_suc__t" id="info">结果</h4>
</div>
</div>
</div>
<div class="act-dialog_ft">
<button class="act-dialog_btn__confirm" onClick="closemsg();">确定</button>
</div>
</div>
</div>
<div class="pop pop1" style="display: none;">
  <p class="error"><br />
  </p>
</div>
<script type="text/javascript">
	
	//提示窗口
	function errShow(content){
		$('.error').html(content);
		$('.pop1').show();
		setTimeout("errHide()",1000);
	}
	
	//隐藏错误提示
	function errHide(){
		$('.pop1').hide();
		$('.error').text('');
		$("#error").html('');
		;
	}
	
	//登陆提示
	function loginShow(content){
		$('.error').html(content);
		$('.pop1').show();
	}
</script> 
<script type="text/javascript">
function checkEmail(str){
    var re1 = /^1\d{10}$/
    var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(re.test(str)){
        return true;
    }else if(re1.test(str)){
        return true;
    }else{
	return false;
	}
}
function firm(){
    var cashmaoney = $("#moneynum").val();
	var shiji = cashmaoney-1;
	  //var cash_tip = '\n本次提现支付宝公司需要收取1元手续费，实际到账'+shiji+'元。\n如果您是第一次提现，免手续费哦！';
	  var cash_tip ='';
    if(confirm("请确认您的支付宝已经通过实名认证，且填写的名字一致，否则无法收款！"+cash_tip))
    {
        send(2);
    }
}
	$(function() {
		var money=<?php echo $config['ti']?>;
		$("#moneynum").bind( "blur", function() {
					if ($("#moneynum").val() == '') {
						errShow("提现金额不能为空！",1);
					} else {
						if ($("#moneynum").val() < money) {
							errShow("提现金额不能低于<?php echo $config['ti']?>元", 1);
							$("#moneynum").focus();
							return false;
						} else {
							return true;
						}
					}

				});
		$("#name").bind( "blur", function() {
			if ($("#name").val() == '') {
				errShow("收款人不能为空！",1);
			}
		});
		$("#account").bind( "blur", function() {
		if ($("#account").val() == '') {
				errShow("提现账号不能为空！",1);
			}
		});
		$("#account1").bind( "blur", function() {
			if ($("#account1").val() == '') {
				errShow("提现账号不能为空！",1);
			}
			if ($("#account1").val() != $("#account").val()) {
				errShow("提现账号不一致！",1);
			}
		});
	})
	function send(num) {
		var money=<?php echo $config['ti']?>;
		var moneynum=$("#moneynum").val();
		var name=$("#name").val();
		var account=$("#account").val();
		var coupon=$("#coupon").val();
			if(moneynum==''){
				errShow("提现金额不能为空！",1);
				return false;
			}else if(moneynum < money){
				errShow("提现金额不能低于<?php echo $config['ti']?>元", 1);
				return false;
			}else if(name==''){
				errShow("收款人不能为空！",1);
				return false;
			}else if(account==''){
				errShow("提现账号不能为空！",1);
				return false;
			}else if(!checkEmail(account)){
			  errShow("支付宝帐号应为邮箱或手机号！",1);
			  return false;
		      //}
		    }else if($("#account1").val() != account){
				errShow("请确认支付宝帐号是否一致！",1);
				return false;
			}else{
	 
				 document.form1.submit();
			 
				
			}

	}
	function closemsg(){
				$("#masks").hide();
				$("#copyurl").hide();
				window.location.href ="/user/pay/cashlist.html"; 
	}

	</script>
<div style="display: none;">
</div>
</div>     </form>
</body>
</html>
